package com.tg.paw.ums.controller;

import com.tg.paw.common.util.CommonResult;
import com.tg.paw.ums.dto.LoginAccountDto;
import com.tg.paw.ums.dto.LoginDto;
import com.tg.paw.ums.enmus.LoginAccountTypeEnum;
import com.tg.paw.ums.params.LoginAccountParam;
import com.tg.paw.ums.service.IApiLoginService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Rubble
 * @date 2020/10/27
 */
@Slf4j
@RestController
@Api(value = "AdminLoginController",tags = "管理员登录注册")
public class AdminLoginController {



    @Autowired
    private IApiLoginService apiLoginService;

    @PostMapping("/api/ums/login/account")
    public CommonResult loginAccount(@RequestBody LoginAccountParam param){
        LoginAccountDto loginDto = new LoginAccountDto();
        loginDto.setType(param.getType().name());
        switch (param.getType()){
            case account:{
                loginDto = apiLoginService.loginByAccount(param);
                break;
            }case mobile:{
                loginDto = apiLoginService.loginByMobile(param);
                break;
            }case alipay:{
                loginDto.setStatus("error");
                loginDto.setMessage("暂不支持的类型 alipay");
                break;
            }case wechat:{
                loginDto.setStatus("error");
                loginDto.setMessage("暂不支持的类型 wechat");
                break;
            } default:{
                return CommonResult.failed("不支持的类型");
            }
        }

        log.info("LoginAccountTypeEnum param {}",param);

        return CommonResult.success(loginDto);
    }
}
